package com.fnzn.entranceGuard.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.fnzn.entranceGuard.entity.GuardQrInfo;
import com.fnzn.entranceGuard.mapper.GuardQrInfoMapper;
import com.fnzn.entranceGuard.service.IGuardQrInfoService;
import com.github.pig.common.constant.CommonConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sxf
 * @since 2018-06-25
 */
@Service
public class GuardQrInfoServiceImpl extends ServiceImpl<GuardQrInfoMapper, GuardQrInfo> implements IGuardQrInfoService {
    @Autowired
    private GuardQrInfoMapper qrInfoMapper;


    @Override
    public void updateByContent(String content, String status, String des, Integer type,String deviceId) {
        qrInfoMapper.updateByContent(content,status,des,type,deviceId);
    }

    /**
     * 通过二维码内容获取用户信息
     * @param qrInfo
     * @return
     */
    @Override
    public GuardQrInfo getByContent(String qrInfo) {
        Wrapper wrapper = new EntityWrapper();
        wrapper.eq(CommonConstant.DEL_FLAG,CommonConstant.STATUS_NORMAL);
        wrapper.eq("content",qrInfo);
        List<GuardQrInfo> list = this.selectList(wrapper);
        if(list!=null && !list.isEmpty()){
            return list.get(0);
        }
        return null;
    }
}
